package org.agent.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.agent.common.Constants;
import org.agent.pojo.User;
import org.agent.service.user.UserService;
import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class BaseAction extends ActionSupport {
	private UserService userService;
	
	private PrintWriter out;
	private User currentUser;//当前用户
	private String actionMessage;//要输出的信息
	//初始化的构造
	public BaseAction () {
		
		try {
			//获取用户
			this.setCurrentUser((User) this.getRequest().getSession().getAttribute(Constants.SESSION_USER));
			//为防止乱码：
			this.getResponse().setCharacterEncoding("utf-8");
			this.out = this.getResponse().getWriter();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	
	public HttpServletResponse getResponse() {
		return ServletActionContext.getResponse();
	}
	public HttpServletRequest getRequest() {
		return ServletActionContext.getRequest();
	}

	

	public UserService getUserService() {
		return userService;
	}
	public void setUserService(UserService userService) {
		this.userService = userService;
	}
	public User getCurrentUser() {
		return currentUser;
	}
	public void setCurrentUser(User currentUser) {
		this.currentUser = currentUser;
	}
	public String getActionMessage() {
		return actionMessage;
	}
	public void setActionMessage(String actionMessage) {
		this.actionMessage = actionMessage;
	}

	public PrintWriter getOut() {
		return out;
	}

	public void setOut(PrintWriter out) {
		this.out = out;
	}

	
	
	
	
}
